<!DOCTYPE html>












  


<html class="theme-next mist use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=6.7.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.7.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.7.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.7.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.7.0" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '6.7.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="背景 使用kafka作为消息队列，将信息收集起来 已有程序无需修改，改起来成本太高了满足这两个条件，首先想到的就是用nginx把数据转发出去，这样程序不用改动，只改变运维环境就可以了。">
<meta name="keywords" content="openresty,lua,kafka">
<meta property="og:type" content="article">
<meta property="og:title" content="openresty+lua+kafka部署">
<meta property="og:url" content="https://www.xingjiehu.com/2020/02/26/cktnq12mx002bx0trvptsk5vk/index.html">
<meta property="og:site_name" content="shooke&#39;s blog">
<meta property="og:description" content="背景 使用kafka作为消息队列，将信息收集起来 已有程序无需修改，改起来成本太高了满足这两个条件，首先想到的就是用nginx把数据转发出去，这样程序不用改动，只改变运维环境就可以了。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2021-09-15T08:59:28.701Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="openresty+lua+kafka部署">
<meta name="twitter:description" content="背景 使用kafka作为消息队列，将信息收集起来 已有程序无需修改，改起来成本太高了满足这两个条件，首先想到的就是用nginx把数据转发出去，这样程序不用改动，只改变运维环境就可以了。">



  <link rel="alternate" href="/atom.xml" title="shooke's blog" type="application/atom+xml">




  <link rel="canonical" href="https://www.xingjiehu.com/2020/02/26/cktnq12mx002bx0trvptsk5vk/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>openresty+lua+kafka部署 - shooke's blog</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <!-- google 验证 -->
  <meta name="google-site-verification" content="9Y6X9yptaHlOdppRk7mld_uHsSibf3lPB8c_60zPyF0">
  <!-- baidu 验证和收录推送 -->
  <meta name="baidu-site-verification" content="lCJxAeYryx">
</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">shooke's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://www.xingjiehu.com/2020/02/26/cktnq12mx002bx0trvptsk5vk/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="shooke">
      <meta itemprop="description" content="平时写点技术文章，分享一些经验，予人玫瑰手有余香">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="shooke's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">openresty+lua+kafka部署

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2020-02-26 17:59:07" itemprop="dateCreated datePublished" datetime="2020-02-26T17:59:07+08:00">2020-02-26</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2021-09-15 16:59:28" itemprop="dateModified" datetime="2021-09-15T16:59:28+08:00">2021-09-15</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing"><a href="/categories/笔记/" itemprop="url" rel="index"><span itemprop="name">笔记</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><ol>
<li>使用kafka作为消息队列，将信息收集起来</li>
<li>已有程序无需修改，改起来成本太高了<br>满足这两个条件，首先想到的就是用nginx把数据转发出去，这样程序不用改动，只改变运维环境就可以了。</li>
</ol>
<a id="more"></a>
<h2 id="安装openresty"><a href="#安装openresty" class="headerlink" title="安装openresty"></a>安装openresty</h2><p>openresty源码安装的过程中，与服务器上的包依赖有冲突。所以改用apt方式安装。很简单。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># 安装导入 GPG 公钥时所需的几个依赖包（整个安装过程完成后可以随时删除它们）：</span><br><span class="line">sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates</span><br><span class="line"></span><br><span class="line"># 导入我们的 GPG 密钥：</span><br><span class="line">wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -</span><br><span class="line"></span><br><span class="line"># 安装 add-apt-repository 命令</span><br><span class="line"># （之后你可以删除这个包以及对应的关联包）</span><br><span class="line">sudo apt-get -y install --no-install-recommends software-properties-common</span><br><span class="line"></span><br><span class="line"># 添加我们官方 official APT 仓库：</span><br><span class="line">sudo add-apt-repository -y &quot;deb http://openresty.org/package/ubuntu $(lsb_release -sc) main&quot;</span><br><span class="line"></span><br><span class="line"># 更新 APT 索引：</span><br><span class="line">sudo apt-get update</span><br><span class="line"></span><br><span class="line"># 安装openresty</span><br><span class="line">sudo apt-get -y install openresty</span><br></pre></td></tr></table></figure></p>
<h2 id="安装kafka"><a href="#安装kafka" class="headerlink" title="安装kafka"></a>安装kafka</h2><ol>
<li>下载kafka<br>进入Apache官网<a href="http://kafka.apache.org/downloads.html" target="_blank" rel="noopener">http://kafka.apache.org/downloads.html</a></li>
</ol>
<p>找到<code>Binary downloads</code>，选择版本进行下载。</p>
<p>也可以复制下载链接，然后用<code>wget</code>下载<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://apache.01link.hk/kafka/2.0.0/kafka_2.11-2.0.0.tgz</span><br></pre></td></tr></table></figure></p>
<ol start="2">
<li>解压程序包<br>压缩包下载后先移动到<code>/opt</code>目录，这是我的习惯，自己安装的放到<code>/opt</code>目录下建一个软件目录，比如<code>/opt/kafka</code>,这样方便管理<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mv kafka_2.11-2.0.0.tgz /opt</span><br><span class="line">cd /opt</span><br><span class="line">tar -xzf kafka_2.11-2.0.0.tgz</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>这样kafka就安装完了，安装目录就是<code>/opt/kafka_2.11-2.0.0</code></p>
<p>3.配置hosts文件<br>将本机的局域网ip和127.0.0.1都配置上,否则会造成kafka无法启动。kafka启动过程中会根据当前主机名进行解析，如果不设置会报错<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># shooke-pc是我的主机名，ip和主机名根据具体情况配置</span><br><span class="line">192.168.99.36 shooke-pc</span><br><span class="line">127.0.0.1 shooke-pc</span><br></pre></td></tr></table></figure></p>
<ol start="3">
<li>启动kafka服务</li>
</ol>
<p>启动zookeeper<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/opt/kafka_2.11-2.0.0/bin/zookeeper-server-start.sh  /opt/kafka_2.11-2.0.0/config/zookeeper.properties</span><br></pre></td></tr></table></figure></p>
<p>kafka依赖zookeeper的，如果有自己的zookeeper服务，可以不启动这个。</p>
<p>启动kafka<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/opt/kafka_2.11-2.0.0/bin/kafka-server-start.sh  /opt/kafka_2.11-2.0.0/config/server.properties</span><br></pre></td></tr></table></figure></p>
<p>这样kafka服务就启动了。</p>
<blockquote>
<p>如果希望后台运行可以加<code>-daemon</code>参数，或用<code>nohup</code>去实现效果</p>
</blockquote>
<h2 id="安装lua-resty-kafka"><a href="#安装lua-resty-kafka" class="headerlink" title="安装lua-resty-kafka"></a>安装lua-resty-kafka</h2><p><code>lua-resty-kafka</code>是<code>openresty</code>和<code>kafka</code>的桥梁。安装了这个插件就可以让<code>openresty</code>吧数据转发到<code>kafka</code>了。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># 下载插件</span><br><span class="line">wget https://github.com/doujiang24/lua-resty-kafka/archive/master.zip</span><br><span class="line"># 解压</span><br><span class="line">unzip master.zip</span><br><span class="line"># 老规矩自己装的软件放到/opt目录</span><br><span class="line">mv lua-resty-kafka-master /opt/lua-resty-kafka</span><br></pre></td></tr></table></figure></p>
<h2 id="让openresty和kafka建立联系"><a href="#让openresty和kafka建立联系" class="headerlink" title="让openresty和kafka建立联系"></a>让openresty和kafka建立联系</h2><p>1.配置kafka</p>
<p>修改<code>/opt/kafka_2.11-2.0.0/config/server.properties</code>，找到<code>listeners</code>，根据具体情况修改<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 这个ip地址是kafka在内网的地址，记住这个ip，下面nginx配置中也会用到，一定要对应</span><br><span class="line">listeners=PLAINTEXT://192.168.99.36:9092</span><br></pre></td></tr></table></figure></p>
<p>2.配置nginx</p>
<p>接下来配置openresty的nginx，让nginx和kafka联系起来<br>修改<code>/etc/openresty/nginx.conf</code> 在http节点内添加如下内容<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">    # 配置个负载均衡方便测试</span><br><span class="line">    upstream apps &#123;</span><br><span class="line">        keepalive 80;</span><br><span class="line">        server 127.0.0.1:8078;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    # `lua-resty-kafka`路径</span><br><span class="line">    lua_package_path &quot;/opt/lua-resty-kafka/lib/?.lua;/opt/lua-resty-http/lib/?.lua;&quot;;</span><br><span class="line">  </span><br><span class="line">    server &#123;</span><br><span class="line">        listen       8077;</span><br><span class="line">        server_name  localhost;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line"></span><br><span class="line">            proxy_next_upstream http_502 http_504 http_404 error invalid_header;</span><br><span class="line">            # 负载均衡</span><br><span class="line">            proxy_pass http://apps;</span><br><span class="line">            proxy_http_version 1.1;</span><br><span class="line">            proxy_redirect off;</span><br><span class="line">            proxy_set_header Upgrade $http_upgrade;</span><br><span class="line">            proxy_set_header Connection &quot;upgrade&quot;;</span><br><span class="line">            proxy_set_header Host $host;</span><br><span class="line">            #proxy_set_header Connection &quot;&quot;;</span><br><span class="line">            proxy_set_header X-real-ip $remote_addr;</span><br><span class="line">            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line">            # 编写lua脚本</span><br><span class="line">            log_by_lua &apos;</span><br><span class="line">                local cjson = require &quot;cjson&quot;</span><br><span class="line">                local producer = require &quot;resty.kafka.producer&quot;</span><br><span class="line">                local broker_list = &#123;</span><br><span class="line">                  &#123; host = &quot;192.168.99.36&quot;, port = 9092 &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                local topic = &quot;logs&quot;</span><br><span class="line">                local log_json = &#123;&#125;</span><br><span class="line">                log_json[&quot;uri&quot;]=ngx.var.uri</span><br><span class="line">                log_json[&quot;args&quot;]=ngx.var.args</span><br><span class="line">                log_json[&quot;host&quot;]=ngx.var.host</span><br><span class="line">                log_json[&quot;cookie&quot;]=ngx.var.http_cookie</span><br><span class="line">                log_json[&quot;method&quot;]=ngx.var.request_method</span><br><span class="line">                log_json[&quot;request_body&quot;]=ngx.var.request_body</span><br><span class="line">                log_json[&quot;remote_addr&quot;] = ngx.var.remote_addr</span><br><span class="line">                log_json[&quot;remote_user&quot;] = ngx.var.remote_user</span><br><span class="line">                log_json[&quot;time_local&quot;] = ngx.var.time_local</span><br><span class="line">                log_json[&quot;status&quot;] = ngx.var.status</span><br><span class="line">                log_json[&quot;body_bytes_sent&quot;] = ngx.var.body_bytes_sent</span><br><span class="line">                log_json[&quot;http_referer&quot;] = ngx.var.http_referer</span><br><span class="line">                log_json[&quot;http_user_agent&quot;] = ngx.var.http_user_agent</span><br><span class="line">                log_json[&quot;http_x_forwarded_for&quot;] = ngx.var.http_x_forwarded_for</span><br><span class="line">                log_json[&quot;upstream_response_time&quot;] = ngx.var.upstream_response_time</span><br><span class="line">                log_json[&quot;http_current_user&quot;] = ngx.var.upstream_http_x_current_user</span><br><span class="line">                log_json[&quot;request_time&quot;] = ngx.var.request_time</span><br><span class="line">                local postargs = ngx.req.get_body_data()</span><br><span class="line">		            log_json[&quot;post_data&quot;] = postargs</span><br><span class="line">                log_json[&quot;res_body&quot;] = ngx.var</span><br><span class="line">                local message = cjson.encode(log_json);</span><br><span class="line">                local bp = producer:new(broker_list, &#123; producer_type = &quot;async&quot; &#125;)</span><br><span class="line">                local ok, err = bp:send(topic, nil, message)</span><br><span class="line">                if not ok then</span><br><span class="line">                    ngx.log(ngx.ERR, &quot;kafka send err:&quot;, err)</span><br><span class="line">                    return</span><br><span class="line">                end</span><br><span class="line">            &apos;;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    server &#123;</span><br><span class="line">        listen    8078;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">          content_by_lua &apos;ngx.say(&quot;hello world&quot;)&apos;;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>设置完成后执行<code>systemctl restart openresty</code>重启服务就好了。访问8077端口请求会转发到kafka。<br>让nginx配置生效也可以执行<code>/usr/local/openresty/nginx/sbin/nginx -s reload</code></p>
<h2 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h2><p>1.<code>/etc/hosts</code>文件要配置上ip和主机名，否则kafka会无法启动报错找不到<br>2.kafka <code>server.properties</code>中<code>listeners</code>的ip要跟nginx配置的<code>broker_list</code>中<code>host</code>一致，否则会报错</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p><a href="https://www.cnblogs.com/expiator/p/9990171.html" target="_blank" rel="noopener">https://www.cnblogs.com/expiator/p/9990171.html</a><br><a href="https://blog.csdn.net/qq_29497387/article/details/101290378" target="_blank" rel="noopener">https://blog.csdn.net/qq_29497387/article/details/101290378</a><br><a href="https://blog.csdn.net/u011239989/article/details/52239785" target="_blank" rel="noopener">https://blog.csdn.net/u011239989/article/details/52239785</a><br><a href="https://blog.csdn.net/qq_29497387/article/details/99745903" target="_blank" rel="noopener">https://blog.csdn.net/qq_29497387/article/details/99745903</a></p>

      
    </div>

    

    
    
    

    

    
      
    
    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <!--
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>领红包</span>
  </button>
  -->
  <div id="QR" style="display: block;">

    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/assets/images/alipay_redpack.png" alt="shooke 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/openresty/" rel="tag"># openresty</a>
          
            <a href="/tags/lua/" rel="tag"># lua</a>
          
            <a href="/tags/kafka/" rel="tag"># kafka</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/02/14/cktnq12n7002xx0trp0zwma7r/" rel="next" title="python mysql-connector简要说明">
                <i class="fa fa-chevron-left"></i> python mysql-connector简要说明
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/03/03/cktnq12tp00cwx0trby0j8lac/" rel="prev" title="1.docker基础概念">
                1.docker基础概念 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">shooke</p>
              <p class="site-description motion-element" itemprop="description">平时写点技术文章，分享一些经验，予人玫瑰手有余香</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">89</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">6</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">111</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/shooke" title="GitHub &rarr; https://github.com/shooke" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://weibo.com/shooke" title="Weibo &rarr; https://weibo.com/shooke" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#背景"><span class="nav-number">1.</span> <span class="nav-text">背景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装openresty"><span class="nav-number">2.</span> <span class="nav-text">安装openresty</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装kafka"><span class="nav-number">3.</span> <span class="nav-text">安装kafka</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装lua-resty-kafka"><span class="nav-number">4.</span> <span class="nav-text">安装lua-resty-kafka</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#让openresty和kafka建立联系"><span class="nav-number">5.</span> <span class="nav-text">让openresty和kafka建立联系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注意事项"><span class="nav-number">6.</span> <span class="nav-text">注意事项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考资料"><span class="nav-number">7.</span> <span class="nav-text">参考资料</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">shooke</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v6.7.0</div>





    <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d6b6833304116ed43a46f8f77b49d030";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=6.7.0"></script>

  <script src="/js/src/motion.js?v=6.7.0"></script>



  
  


  <script src="/js/src/schemes/muse.js?v=6.7.0"></script>




  
  <script src="/js/src/scrollspy.js?v=6.7.0"></script>
<script src="/js/src/post-details.js?v=6.7.0"></script>



  


  <script src="/js/src/bootstrap.js?v=6.7.0"></script>



  


  


  





  

  

  
  <script>
  (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
          bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else {
          bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>


  

  

  

  

  

  

  

  

  

  

</body>
</html>
